<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Access_control {

	public $CI;
    public $error;

    public function __construct()
    {
        $this->CI =& get_instance();
    }

    //$access_id[string]    控制器方法权限
    //$right_ids[array]     用户拥有的权限
    //重写于 2012-10-29 16:10
    public function base($access_id, $right_ids, $error='')
    {
        if (!empty($error) && is_string($error))
        {
            $this->error = $error;
        }
        else
        {
            $this->error = 'System: 无效的自定义错误提示';
        }

        if (!$right_ids)
        {
            return FALSE;
        }
        else if (in_array($access_id, $right_ids) || in_array(1, $right_ids))
        {
            return TRUE;
        }
        else if ($this->root($right_ids))
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

    private function root($u)
    {
        if (in_array('0', $u)) return TRUE;
        return FALSE;
    }

}

?>